﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script src="/../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.tools.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.pajinate.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.pajinate.js" type="text/javascript"></script>
    <script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <script type="text/javascript">
        var directionDisplay;
        var directionsService = new google.maps.DirectionsService();
        var map;
        var haight = new google.maps.LatLng(10.843928, 106.717672);
        var oceanBeach;
        // var oceanBeach = new google.maps.LatLng(10.843928, 106.717672);
        navigator.geolocation.getCurrentPosition(function (position) {
            oceanBeach = new google.maps.LatLng(position.coords.latitude,
            position.coords.longitude);
        });
        function initialize() {
            directionsDisplay = new google.maps.DirectionsRenderer();
            var myOptions = {
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: haight
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
            directionsDisplay.setMap(map);
        }

        function calcRoute() {
            initialize();
            var des1 = document.getElementById("memAddLat").innerText;
            var des2 = document.getElementById("memAddLong").innerText;
            var des = new google.maps.LatLng(des1, des2);
            var request = {
                origin: oceanBeach,
                destination: des,
                // Note that Javascript allows us to access the constant
                // using square brackets and a string value as its
                // "property."
                travelMode: google.maps.DirectionsTravelMode["DRIVING"]
            };
            directionsService.route(request, function (response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                }
            });
        }
    </script>
    <script type="text/javascript">
        var lastReplyHidden = null;
        jQuery(document).ready(function () {
            RegisterReplyButton();
        });
    </script>
    <script type="text/javascript">
    $(document).ready(function () {
       $('#paging_container').pajinate({
	     items_per_page: 9,
        nav_panel_id: '.page_navigation',
        nav_label_first: 'First',
        nav_label_last: 'Last',
        nav_label_prev: 'Trang trước',
        nav_label_next: 'Trang sau',
	});
    });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            var triggers = $(".modalInput").overlay({
                // some mask tweaks suitable for modal dialogs
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },

                closeOnClick: false
            });

            var buttons = $("#yesno button").click(function (e) {

                // get user input
                var yes = buttons.index(this) === 0;

                // do something with the answer
                triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
            });

            $("#prompt form").submit(function (e) {

                // close the overlay
                triggers.eq(1).overlay().close();

                // get user input
                var input = $("input", this).val();

                // do something with the answer
                triggers.eq(1).html(input);

                // do not submit the form
                return e.preventDefault();
            });

            var triggers = $(".modalInput2").overlay({
                // some mask tweaks suitable for modal dialogs
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },

                closeOnClick: false
            });

            var buttons = $("#yesno button").click(function (e) {

                // get user input
                var yes = buttons.index(this) === 0;

                // do something with the answer
                triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
            });

            $("#prompt2 form").submit(function (e) {

                // close the overlay
                triggers.eq(1).overlay().close();

                // get user input
                var input = $("input", this).val();

                // do something with the answer
                triggers.eq(1).html(input);

                // do not submit the form
                return e.preventDefault();
            });

            $("#MapButton").click(function () {
                calcRoute();
            });

            $("#LienHeButton").click(function () {
                var emailfrom = $("#txtUserEmail").val();
                var name = $("#txtUserName").val();
                var sid = $('#LienHeButton').data("url");
                var userid = $("#txtUserId").val();
                if (userid == "")
                    userid = "0";
                var dataString = "mailfrom=" + emailfrom + "&name=" + name + "&memid=" + userid + "&proid=" + sid;
                $.ajax({
                    type: "POST",
                    url: "/NewsProduct/SendEmail",
                    data: dataString,
                    success: function (result) {
                        alert("Thông tin được gởi thành công");
                    },
                    error: function (req, status, error) {
                        alert("Sorry! We could not receive your feedback at this time.");
                    }
                });

            });
        });
    </script>
      <script type="text/javascript">
          function SaveNews(e) {
              var sid = e;
              $.ajax({
                  type: "POST",
                  url: "/NewsProduct/SaveNewsProductMember",
                  data: "newId=" + sid,
                  success: function (result) {

                      if (result == "true") {
                          alert("Lưu tin thành công");
                      }
                      else {
                          alert("Tin này đã được lưu");
                      }
                  },
                  error: function (req, status, error) {
                      alert("Sorry! We could not receive your feedback at this time.");
                  }
              });
          }
    </script>
    <% NewsProduct newsProduct = (NewsProduct)ViewData["NewsProduct"]; %>
    <div class="private_share_post_top">
        <div class="private_sharepost_menu">
            <ul>
                <li><a href="canhan_sp_detail_private.html" class="menu_select">Chia sẽ</a></li>
                <li><a href="#">Bài viết yêu thích</a></li>
            </ul>
        </div>
        <div class="private_write_right">
            <div class="private_bt_newspost">
                <%if (Session["MemId"] != null)
                  {
                %>
                <a href="<%= Url.Action("","Product") %>">
                    <img src="/../Content/Images/icon_newpost.gif" />
                    Viết bài mới... </a>
                <%
                    }
                %>
            </div>
        </div>
    </div>
    <div class="private_comment_top">
        <div class="private_post_text">
            <p class="private_text_title">
                <%= newsProduct == null ? "Chưa có tiêu đề" : newsProduct.NProTitle.ToUpper() %></p>
            <p>
                <span class="private_price">GIÁ:
                    <%= newsProduct == null ? "0 VNĐ" : String.Format("{0:0,0}", newsProduct.NProPrice)%></span>
                <span class="private_price_cur">VND</span><%--<span class="private_price_cur">SJC</span><span class="private_price_cur">USD</span>--%></p>
            <br />
            <p>
                <%= newsProduct == null ? "Chưa có nội dung" : newsProduct.NProContent%></p>
            <br />
            <div id="memAddLat" class="hidden">
                <%=newsProduct.Member.MemAddressLatitude%></div>
            <div id="memAddLong" class="hidden">
                <%=newsProduct.Member.MemAddressLongitude%></div>
            <div class="LikeField">
                Thích: Có
                <%=newsProduct.NProLike%>
                người thích
            </div>
            <div class="private_post_text">
                <div class="hoicho_margin_topbottom">
                    <%--<div class="col_left hoicho_margin_right">--%>
                    <div class=" col_left">
                        <a href="#" class="hoicho_bt_action" id="LikeButton" data-url='<%=newsProduct.NProId %>'>
                            <img class="hoicho_bt_action_image " style="cursor: pointer" align="middle" src="/../Content/Images/like_bt.gif" />
                            Thích</a>
                        <script type="text/javascript">
                            $('#LikeButton').click(function () {
                                var sid = $('#LikeButton').data("url");
                                $.ajax({
                                    type: "POST",
                                    url: "/NewsProduct/Like",
                                    data: "proId=" + sid,
                                    success: function (result) {

                                        if (result == "null") {
                                            alert("Đăng nhập để thích");
                                        }
                                        else {
                                            if (result == "duplicated")
                                                alert("Bạn đã thích rồi");
                                            else
                                                $('.LikeField').html("Thích: Có " + result + " người thích");
                                        }
                                    },
                                    error: function (req, status, error) {
                                        alert("Sorry! We could not receive your feedback at this time.");
                                    }
                                });
                            });
                        </script>
                    </div>
                    <div class="col_left">
                        <%--<div>--%>
                        <a href="#" class="hoicho_bt_action  modalInput2" onclick="calcRoute()" rel="#prompt2">
                            <img class="hoicho_bt_action_image" src="/../Content/Images/hoicho_iconmap.gif" align="bottom" />
                            Bản đồ gian hàng </a>
                    </div>
                    <div class="col_left">
                        <%--<div>--%>
                        <a href="#" class="hoicho_bt_action modalInput" rel="#prompt">
                            <img class="hoicho_bt_action_image " src="/../Content/Images/icon_mail.gif" align="bottom" />
                            Liên hệ mail </a>
                    </div>
                    <%--begin modal pop up --%>
                    <div class="modal" id="prompt">
                        <h2>
                            Thông tin liên hệ</h2>
                        <p>
                            Thông tin này sẽ được gởi mail tới chủ gian hàng
                        </p>
                        <!-- input form. you can press enter too -->
                        <form>
                        <table>
                            <tr>
                                <td>
                                    Id:
                                </td>
                                <td>
                                    <%=Html.TextBox("txtUserId", (Session["MemId"] == null ? "" : Session["MemId"]), new { @class = "lienhe-box" })%>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Họ và tên:
                                </td>
                                <td>
                                    <%=Html.TextBox("txtUserName", (Session["MemUserName"] == null ? "" : Session["MemUserName"]), new { @class = "lienhe-box" })%>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Địa chỉ Email:
                                </td>
                                <td>
                                    <%=Html.TextBox("txtUserEmail",(Session["MemUserEmail"]==null? "":Session["MemUserEmail"]),new { @class = "lienhe-box"}) %>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Nội dung:
                                </td>
                                <td>
                                    <%=Html.TextArea("txtUserNoiDung","",new { @class = "lienhe-textarea"}) %>
                                </td>
                            </tr>
                        </table>
                        <input type="button" id="LienHeButton" class="private_bt_submit_news" value="Gởi" data-url='<%=newsProduct.NProId %>' />
                        <button type="button" style="margin:5px;" class="close private_bt_submit_news">
                            Cancel
                        </button>
                        </form>
                        <br />
                    </div>
                    <%--end modal popup--%>
                    <%--begin modal map--%>
                    <div class="modal2" id="prompt2">
                        <h2>
                            Thông tin Map</h2>
                        <!-- input form. you can press enter too -->
                        <form>
                     <%--    <input type="button" id="MapButton" class="private_bt_submit_news" value="Gởi" data-url='<%=newsProduct.NProId %>' />--%>
                        <button type="button" class="close private_bt_submit_news">
                            Cancel
                        </button>
                        <div id="map_canvas" onclick="calcRoute()" style="top: 10px; height: 430px; width: 100%">
                        </div>
                       
                        </form>
                        <br />
                    </div>
                    <%--end modal map--%>
                    <div class="col_left">
                        <%--<div>--%>
                        <a href="#" class="hoicho_bt_action" onclick="SaveNews(<%=newsProduct.NProId %>)">
                            <img class="hoicho_bt_action_image" src="/../Content/Images/icon_save.gif" align="bottom" />
                            Lưu tin </a>
                    </div>
                    <div class="col_left">
                        <a href="#" class="hoicho_bt_action" onclick="window.print();return false;">
                            <img class="hoicho_bt_action_image" src="/../Content/Images/icon_print.gif" align="bottom" />
                            In </a>
                    </div>
                    <div class="clear">
                    </div>
                    <%--<div class="content_group">--%>
                    <div>
                  <%--      <div class="private_logo_share col_left hoicho_margin_right">
                            <!-- AddToAny BEGIN -->
                            <div class="a2a_kit a2a_default_style">
                                <a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=hoichomuaban.com&amp;linkname=Hoi%20Cho%20Mua%20Ban">
                                    Chia sẻ</a> <span class="a2a_divider"></span><a class="a2a_button_facebook">
                                </a><a class="a2a_button_twitter"></a><a class="a2a_button_google_bookmarks"></a>
                                <a class="a2a_button_digg"></a>
                                <!-- AddToAny END -->
                            </div>
                        </div>--%>
                    </div>
                    <div class="clear">
                    </div>
                    <div class="hoicho_margin_topbottom">
                        <%--<div class="content_group hoicho_margin_topbottom">--%>
                        <span class="hoicho_margin_right font_bold">
                            <img src="/../Content/Images/hoicho_icon_by.gif" class="hoicho_margin_right" />Đăng
                            bởi:
                            <%=newsProduct.Member.MemUsername%></span>
                        <div class="private_friend_chat">
                            <strong>Chat:&nbsp;</strong> <a href="ymsgr:sendim?<%=newsProduct.Member.MemYahoo %>">
                                <img style="width: 80px; height: 23px" src="http://opi.yahoo.com/online?u=<%=newsProduct.Member.MemYahoo %>&m=g&t=2"
                                    alt="VinaBlog.blogspot.com" border="0">
                            </a>
                            <!--
Skype 'Chat with me' button
http://www.skype.com/go/skypebuttons
-->
                            <script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script>
                            <a href="skype:<%=newsProduct.Member.MemSkype %>?chat">
                                <img src="http://download.skype.com/share/skypebuttons/buttons/chat_green_transparent_97x23.png"
                                    style="border: none;" width="97" height="23" alt="Chat with me" /></a>
                            <% if (Session["MemId"] != null && newsProduct.Member.MemId != (int)Session["MemId"])
                               { %>
                            <a href="#" onclick="sendMakeFriendRequest('<%=Url.Action("MakeFriend", "Friend") %>', '<%=newsProduct.Member.MemId %>', this); return false;">
                                <img src="/../Content/Images/icon_friends.gif" alt="" /></a>
                            <% } %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <hr class="private_color_hr" />
    <div class="private_coment_group">
        <div class="private_coment_text">
            <a name="comments">Bình luận</a>
        </div>
        <% if (Session["MemId"] != null)
           { %>
        <form action="<%=Url.Action("AddComment", "NewsProduct") %>" method="post" class="private_content_comment">
        <input type="hidden" value="<%=newsProduct.NProId %>" name="newsId" id="newsId" />
        <div class="private_menu_topmenu">
             <textarea class="input_full" rows="5" cols="50" id="txtComment" style="width:550px" name="txtComment"></textarea>
        </div>
        <div class="private_post_text">
            <div style="background-color: white; margin: 10px 0px 10px 0px; width: 550px">
                        <span class="private_font_bold">Chọn icon: </span>
                        <% ChatHelper chat2 = new ChatHelper();
                           List<ChatEmotionDetail> icons2 = chat2.getEmotionPath();
                           foreach (ChatEmotionDetail icon in icons2)
                           {
                               Response.Write("<img align='middle' style='margin:3px' onclick='MemchatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='30px' height='30px' />");

                           }
                        %>
                    </div>
                    <script type="text/javascript">
                        function MemchatIconClick(obj) {
                            $this = document.getElementById("txtComment");
                            $this.value += obj.id;
                        }
                    </script>
            <div class="private_write_right">
                <input type="submit" style="#width: 60px;" id="" value="Gửi" class="private_bt_submit_news_disable" />
            </div>
        </div>
        </form>
        <% } %>
    </div>
    <form action="<%=Url.Action("AddComment", "NewsProduct") %>" method="post" class="private_content_comment"
    style="margin-left: auto; display: none" id="frmReplyTo">
    <input type="button" value="đóng" style="margin-left: 400px" class="btnReplyClose_<%=newsProduct.NProId %>"   onclick="CloseRegisterReplyButton(<%=newsProduct.NProId %>)" />
    <input type="hidden" value="" name="replyTo" id="replyTo" />
    <input type="hidden" value="<%=newsProduct.NProId %>" name="newsId" id="Hidden1" />
    <div class="private_menu_topmenu">
        <textarea  style="margin-left: 20px;width:550px" class="input_full"  rows="5" cols="45" id="ChatArea" name="txtComment"></textarea>
    </div>
    <div class="private_post_text">
        <div class="private_button_left">
            <span class="private_font_bold">Chọn icon: </span>
            <% ChatHelper nchat = new ChatHelper();
               List<ChatEmotionDetail> nicons = nchat.getEmotionPath();
               foreach (ChatEmotionDetail icon in nicons)
               {
                   Response.Write("<img align='middle' onclick='chatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='40px' height='40px' />");

               }
            %>
            <script type="text/javascript">
                function chatIconClick(obj) {
                    $this = document.getElementById("ChatArea");
                    $this.value += obj.id;
                }
                function CloseRegisterReplyButton(e) {
                    jQuery(".btnReplyClose_" + e).click(function () {
                        var msgBox = jQuery(this).parents(".private_messages_text");
                        var frmReplyTo = jQuery("#frmReplyTo");
                        msgBox.append(frmReplyTo.hide());
                        var cmtId = msgBox.find(".commentId");
                        if (cmtId.length == 1)
                            cmtId = cmtId.eq(0).html();
                        frmReplyTo.find("#replyTo").val(cmtId);

                        if (lastReplyHidden != null)
                            lastReplyHidden.show();
                        lastReplyHidden = jQuery(this);
                        jQuery(this).hide();
                        return false;
                    });
                }
            </script>
        </div>
        <div class="private_write_right">
            <input type="submit" style="width: 60px;" id="Submit1" value="Gửi" class="private_bt_submit_news_disable" />
        </div>
    </div>
    </form>
    <div class="clear">
    </div>
    <div id="paging_container" class="container">
        <div class="page_navigation private_breakpage" style="text-align: right">
        </div>
        <ul class="content">
            <%
                //List<NewsProductComment> comments = (from n in news.NewsProductComments
                //                                     where n.ComIdReply == null
                //                                     orderby n.ComDate descending
                //                                     select n).ToList();
                List<NewsProductComment> comments = new NewsProductHelper().getListCommentByProductId(newsProduct.NProId);
                foreach (var com in comments)
                {
            %>
            <!-- Content comment -->
            <li>
                <div class="private_content_mg_thumb">
                    <div class="private_comment_repply">
                        <div class="private_comment_user">
                            <div class="private_img_post_bt">
                                <img class="private_img_post" alt="" width="50" height="50" src="/../Content/Images/Upload/<%=com.Member.MemAvatar %>" />
                            </div>
                            <div class="private_messages_text">
                                <div class="commentId" style="display: none">
                                    <%=com.ComId %></div>
                                <p>
                                    <span class="private_text_title">
                                        <%=com.Member.MemUsername %></span> &nbsp;&nbsp;<span class="private_timer_repply"><%=com.ComDate.ToString("HH:mm | dd.MM.yyyy") %></span></p>
                                <p>
                                    <%=com.ComContent %>
                                </p>
                                <div class="private_link_repply">
                                    <a href="#" class="btnReply">Trả lời</a></div>
                            </div>
                        </div>
                        <div class="clear">
                        </div>
                        <%
//List<NewsProductComment> replies = (from r in com.NewsProductReply
//                                    orderby r.ComDate descending
//                                    select r).ToList();
List<NewsProductComment> replies = new NewsProductHelper().getListCommentReplyByCommentId(com.ComId);
foreach (NewsProductComment r in replies)
{
                        %>
                        <div class="private_admin_reply">
                            <div class="private_arrowtop_adminreply">
                            </div>
                            <div class="private_content_adminreply">
                                <div class="private_img_post_bt">
                                    <img class="private_img_post" alt="" width="50" height="50" src="/../Content/Images/Upload/<%=r.Member.MemAvatar %>" />
                                </div>
                                <div class="private_messages_text">
                                    <p>
                                        <span class="private_user">
                                            <%=r.Member.MemUsername %></span>&nbsp;&nbsp; <span class="private_timer_repply">
                                                <%=r.ComDate.ToString("HH:mm | dd.MM.yyyy") %></span></p>
                                    <p>
                                        <%=r.ComContent %>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <% } %>
                    </div>
                    <hr class="private_color_hr" />
                </div>
                <!-- endContent comment -->
            </li>
            <% } %>
        </ul>
        <div class="page_navigation private_breakpage" style="text-align: right">
        </div>
    </div>
    <hr class="private_color_hr" />
    <div class="private_last_news">
        <div class="boxnew_header">
            <div class="boxnew_title">
                Tin mới</div>
            <div class="clear">
            </div>
            <ul>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
            </ul>
        </div>
    </div>
    <div class="private_last_news">
        <div class="boxnew_header">
            <div class="boxnew_title">
                Tin khác</div>
            <div class="clear">
            </div>
            <ul>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
                <li><a href="#">Tiến Minh khởi đầu thuận lợi ở giải Australia Mở rộng (06/04)</a></li>
            </ul>
        </div>
    </div>
    <hr class="private_color_hr" />
    <center>
        <div class="private_breakpage">
            <a href="#">
                <img alt="" src="/../Content/Images/arrow_breakpage_left.gif">&nbsp;Trang trước</a>
            <a class="menu_select" href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">
                4</a> <a href="#">5</a> <a href="#">6</a> <a href="#">7</a> <a href="#">Trang sau&nbsp;<img
                    alt="" src="/../Content/Images/arrow_breakpage_right.gif"></a>
        </div>
    </center>
</asp:Content>
